package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;

import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * SPH_Demo01
 * 2022/10/31 23 27
 */
@RestController
@RequestMapping("/admin/product")
public class CategoryController {
    @Autowired
    private BaseCategory1Service baseCategory1Service;
    @Autowired
    private BaseCategory2Service baseCategory2Service;
    @Autowired
    private BaseCategory3Service baseCategory3Service;

    /**
     * 查询基本信息的一级分类
     * @return
     */
    @GetMapping("/getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> list1 = baseCategory1Service.list ();
        return Result.ok (list1);
    }

    /**
     * 查询基本信息的二级分类
     * @return
     */
    @GetMapping("/getCategory2/{ids}")
    public Result getCategory2(@PathVariable Long ids){
        QueryWrapper<BaseCategory2> queryWrapper = new QueryWrapper<> ();
        queryWrapper.eq ("category1_id",ids);
        List<BaseCategory2> list = baseCategory2Service.list (queryWrapper);
        return Result.ok (list);
    }

    /**
     * 查询基本信息的三级分类
     * @return
     */
    @GetMapping("/getCategory3/{ids}")
    public Result getCategory3(@PathVariable Long ids){
        QueryWrapper<BaseCategory3> queryWrapper = new QueryWrapper<> ();
        queryWrapper.eq ("category2_id",ids);
        List<BaseCategory3> list = baseCategory3Service.list (queryWrapper);
        return Result.ok (list);
    }


}
